@extends('admin.main')
@section('content')
    <div class="admin-content">
        <div class="am-cf am-padding am-padding-bottom-0">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">后台设置</strong> /
                <small>新增货单</small>
            </div>
        </div>
        <hr>
        <div class="am-g">
            @include('admin.layouts.adminInfo')
            <div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4">
                <form action="{{$prefix_url}}/basic" class="am-form"
                      method="POST" enctype="multipart/form-data">
                    {{csrf_field()}}
                    <input type='hidden' name='_method' value='POST'/>
                    <input type='hidden' name='id'
                           value='{{isset($data)?$data->id:0}}'/>
                    <div class='am-form-group'>
                        <h2>基本信息</h2>
                    </div>
                    <div class='am-form-group'>
                        <label>企业选择(必选)：</label>
                        <select name="uid" required>
                            @foreach($coms as $com)
                            <option value="{{$com->uid}}">
                                {{$com->id}} -- {{$com->com_name}}
                            </option>
                            @endforeach
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>订单产品名称(必填)：</label>
                        <input type="text" name="name" placeholder="订单产品名称"
                               minlength='1' maxlength='20' required
                               value="{{isset($data)?$data->name:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>搜索分类(必选)：</label>
                        <select name="cate" required>
                            @foreach($cates as $cate)
                                <option value="{{$cate['id']}}">
                                    {{$cate['id']}} -- {{$cate['name']}}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>款号(必填)：</label>
                        <input type="text" name="styleNo" placeholder="款号"
                               minlength='1' maxlength='20' required
                               value="{{isset($data)?$data->styleNo:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>款式名称(必填)：</label>
                        <input type="text" name="styleName" placeholder="款式名称"
                               minlength='1' maxlength='20' required
                               value="{{isset($data)?$data->styleName:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>数量(必填)：</label>
                        <input type="text" name="num" placeholder="数量"
                               pattern="\d+" required
                               value="{{isset($data)?$data->num:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>单价(必填)：</label>
                        <input type="text" name="money"
                               placeholder="单价" required
                               pattern="(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)"
                               value="{{isset($data)?$data->money:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>有效期：</label>
                        <input type="text" data-am-datepicker
                               placeholder="点击获取有效期"
                               name="period" readonly>
                    </div>
                    <div class='am-form-group'>
                        <label>外发分类：</label>
                        <div id="outType"></div>
                    </div>
                    <div class='am-form-group'>
                        <label>是否抢单：</label><br>
                        <label>
                            <input type="radio" name="isRob" value="1" required>
                            抢单
                        </label>
                        &nbsp; &nbsp;
                        &nbsp; &nbsp;
                        <label>
                            <input type="radio" name="isRob" value="2" required>
                            普通单
                        </label>
                    </div>
                    <div class='am-form-group'>
                        <label>是否提供原料面料：</label><br>
                        <label>
                            <input type="radio" name="isFabric" value="1" required>
                            不提供
                        </label>
                        &nbsp; &nbsp;
                        <label>
                            <input type="radio" name="isFabric" value="2" required>
                            提供但未填写
                        </label>
                        &nbsp; &nbsp;
                        <label>
                            <input type="radio" name="isFabric" value="3" required>
                            提供并已填写
                        </label>
                    </div>
                    <div class='am-form-group'>
                        <label>是否提供原料面料：</label><br>
                        <label>
                            <input type="radio" name="isContract" value="1" required>
                            未上传
                        </label>
                        &nbsp; &nbsp;
                        <label>
                            <input type="radio" name="isContract" value="2" required>
                            发单方上传
                        </label>
                        &nbsp; &nbsp;
                        <label>
                            <input type="radio" name="isContract" value="3" required>
                            合作方上传
                        </label>
                    </div>
                    <div class='am-form-group'>
                        <label>适用场景：</label>
                        <input type="text" name="scence" placeholder="适用场景"
                               minlength='1' maxlength='200'
                               value="{{isset($data)?$data->scence:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>材质：</label>
                        <input type="text" name="material" placeholder="材质"
                               minlength='1' maxlength='200'
                               value="{{isset($data)?$data->material:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>工艺要求：</label>
                        <input type="text" name="tech" placeholder="工艺要求"
                               minlength='1' maxlength='200'
                               value="{{isset($data)?$data->tech:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>货单描述：</label>
                        <textarea name="detail" placeholder="货单描述"
                                  minlength='1' maxlength='200'
                            >{{isset($data)?$data->detail:''}}</textarea>
                    </div>
                    <div class='am-form-group'>
                        <h2>基本信息</h2>
                    </div>
                    {{--提交按钮--}}
                    <button type='button' class='am-btn am-btn-primary'
                            onclick='history.go(-1);'>返回</button>
                    <br><br>
                    <button type='button' class='am-btn am-btn-primary'
                            onclick="alert('已经在此页！')">
                        基本信息
                    </button>
                    >
                    <button type='submit' class='am-btn am-btn-primary'>
                        其他信息</button>
                    >
                    <button type='button' class='am-btn am-btn-primary'
                            onclick="alert('还未填写其他信息！')">
                        保存</button>
                </form>
                <br><br>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        (function(){
            getOutTypes(1);
        })();
        $('select[name="cate"]').on('change',function(){
            var cate = $('select[name="cate"]').val();
            getOutTypes(cate);
        });
        //外发分类
        function getOutTypes(cate){
            $.ajaxSetup({
                headers: { 'X-CSRF-TOKEN':$("input[name='_token']").val() }
            });
            var formData = {
                cate:cate
            };
            $.ajax({
                type:'post',
                dataType:'json',
                url:getPrefix()+'/basic/outType',
                data:formData,
                success:function(res){
                    //console.log(res); return
                    if (res.code!=0) {
                        console.log(res.msg);
                        return
                    }
                    console.log(res.data);
                    var resData = res.data;
                    var i, h = '';
                    for (i=0;i<resData.length;i++) {
                        h += '<label>';
                        h += '<input type="checkbox" name="outTypes[]" value="'+resData[i].id+'">';
                        h += ' '+resData[i].name;
                        h += '&nbsp; &nbsp; &nbsp; &nbsp;';
                        h += '</label>';
                    }
                    $('#outType').html(h);
                },
                error:function(){
                    console.log('操作失败！');
                }
            });
        }
//        //日期组件
//        $(function() {
//            $('.doc-datepicker').datepicker().
//            on('changeDate.datepicker.amui', function(event) {
//                console.log(event.date);
//            });
//        });
        $('input[name="period"]').on('click',function(){
            $('input[name="period"]').datepicker().
            on('changeDate.datepicker.amui', function(event) {
                console.log(event.date);
            });
        });
//        //点击保存基本信息
//        function setBasic(){
//            var id = $('input[name="id"]').val();
//            var uid = $('select[name="uid"]').val();
//            var name = $('input[name="name"]').val();
//            var cate = $('select[name="cate"]').val();
//            var styleNo = $('input[name="styleNo"]').val();
//            var styleName = $('input[name="styleName"]').val();
//            var num = $('input[name="num"]').val();
//            var money = $('input[name="money"]').val();
//            var scence = $('input[name="scence"]').val();
//            var material = $('input[name="material"]').val();
//            var tech = $('input[name="tech"]').val();
//            if (!uid || !name || !cate || !styleNo ||
//                    !styleName || !num || !money) {
//                alert('必填信息不全！'); return
//            }
//            scence = scence?scence:'';
//            material = material?material:'';
//            tech = tech?tech:'';
//            var formData = {
//                id:id,
//                uid:uid,
//                name:name,
//                cate:cate,
//                styleNo:styleNo,
//                styleName:styleName,
//                num:num,
//                money:money,
//                scence:scence,
//                material:material,
//                tech:tech
//            };
////            console.log(formData); return
//            $.ajaxSetup({
//                headers: { 'X-CSRF-TOKEN':$("input[name='_token']").val() }
//            });
//            $.ajax({
//                type:'post',
//                dataType:'json',
//                url:getPrefix()+'/basic',
//                data:formData,
//                success:function(res){
//                    console.log(res); return
//                    if (res.code!=0) {
//                        console.log(res.msg);
//                        return
//                    }
//                    console.log(res);
//                },
//                error:function(){
//                    console.log('操作失败！');
//                }
//            });
//        }
        //请求地址
        function getPrefix(){
            return '/mcadmin/basic/order/bale';
        }
    </script>
@stop